//
//  CompleteOrderViewController.m
//  SeaMelonSeeds_Counselor
//
//  Created by 尤振宇 on 2017/8/3.
//  Copyright © 2017年 杨笑. All rights reserved.
//

#import "CompleteOrderViewController.h"
#import "MoreButtonView.h"
#import "CompleteOrderClassificationVC.h"

@interface CompleteOrderViewController () <MoreButtonViewDelegate,UIScrollViewDelegate>
@property(nonatomic,strong)UIScrollView *scrollView;
@property(nonatomic,strong)MoreButtonView *moreView;
@end

@implementation CompleteOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"已完成订单";
    [self initView];
    // Do any additional setup after loading the view.
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    [self.scrollView setContentSize:CGSizeMake(SCREEN_WIDTH * [self types].count, self.scrollView.height)];
}

-(void)initView
{
    [self.view addSubview:self.moreView];
    [self.moreView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(64);
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.height.equalTo(@40);
    }];
    
    UIView *line = [[UIView alloc]init];
    line.backgroundColor = kF2F2F2;
    [self.view addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.moreView.mas_bottom);
        make.right.equalTo(self.moreView);
        make.width.equalTo(self.moreView);
        make.height.equalTo(@5);
    }];
    
    [self.view addSubview:self.scrollView];
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(line.mas_bottom);
        make.right.equalTo(self.moreView);
        make.width.equalTo(self.moreView);
        make.bottom.equalTo(self.view);
    }];
    
    for (int i = 0; i < [self types].count; i++) {
        OrderType type = [[self types][i] integerValue];
        
        CompleteOrderClassificationVC *vc = [[CompleteOrderClassificationVC alloc]initWithType:type];
        
        [self addChildViewController:vc];
        [self.scrollView addSubview:vc.view];
        
        [vc.view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.scrollView);
            make.leading.equalTo(@(SCREEN_WIDTH * i));
            make.width.equalTo(self.scrollView);
            make.height.equalTo(self.scrollView);
        }];
    }
}

-(NSArray *)types
{
    return @[@(tuwen_OrderType),@(yuyin_OrderType),@(shipin_OrderType),@(mianduimian_OrderType)];
}

-(void)touchUpInsideButtonActionIndex:(NSInteger)index title:(NSString *)title sameIndex:(BOOL)sameIndex
{
    if (!sameIndex) {
        [self.scrollView setContentOffset:CGPointMake(SCREEN_WIDTH * index, 0) animated:YES];
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
{
    int index = scrollView.contentOffset.x / scrollView.width;
    [self.moreView moveLine:[self.moreView buttonWithIndex:index]];
}

-(UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]init];
        _scrollView.showsVerticalScrollIndicator = NO;
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.bounces = NO;
        _scrollView.pagingEnabled = YES;
        _scrollView.delegate = self;
    }
    return _scrollView;
}

-(MoreButtonView *)moreView
{
    if (!_moreView) {
        _moreView = [[MoreButtonView alloc]init];
        _moreView.scrollView.scrollEnabled = NO;
        
        _moreView.moreButtonViewDelegate = self;
        [_moreView setTitles:@[@"图文",@"语音",@"视频",@"面对面"]];
        _moreView.lineH = 2;
        _moreView.lineWEqualTitleW = YES;
        _moreView.lineYOffset = -6;
        
        UIColor *color = k65ACFE;
        _moreView.lineColor = color;
        _moreView.selectedTitleColor = color;
        _moreView.titleColor = [UIColor blackColor];
    }
    return _moreView;
}
@end
